<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  methods: {
    async checkToken () {
      const token = localStorage.getItem('token')
      if (token !== null && token !== '') {
        try {
          const res = await this.$http.post('/ajserver/oauth/check_token?token=' + token)
          if (res.status !== 200) {
            console.log('状态异常')
          }
          const { data: info } = await this.$http.post('/ajshow/user/info')
          if (!info.status) {
            localStorage.removeItem('token')
            localStorage.removeItem('refresh_token')
            localStorage.removeItem('userInfo')
            localStorage.removeItem('active')
            await this.$router.push('/login')
          }
        } catch (e) {
          console.log(e.toString())
          localStorage.removeItem('token')
          localStorage.removeItem('refresh_token')
          localStorage.removeItem('userInfo')
          localStorage.removeItem('active')
          await this.$router.push('/login')
        }
      }
    }
  },
  // 一进来就先加载
  mounted () {
    this.checkToken()
    // setInterval(this.checkToken, 10000)
  }
}
</script>

<style lang="less">
/*
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
*/
</style>
